package com.chengjue.rocketmq.manager;

import com.chengjue.rocketmq.listener.MessageListener;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;

import java.util.List;

/**
 * @Author: Kipeng Huang
 * @Date: 2018-4-12 15:55
 *
 */
public class RocketMQManager {

    public RocketMQManager(DefaultMQPushConsumer mqConsumer, List<MessageListener> messageListeners, String topic, String tag) {
        try {
            mqConsumer.subscribe(topic, tag);
            messageListeners.forEach(messageListener -> mqConsumer.registerMessageListener(messageListener));
            mqConsumer.start();
        } catch (MQClientException e) {
            e.printStackTrace();
        }
    }

}
